<?php
	$works = []; //进程池
	$worker_num = 2; //最大进程数
	for ($i = 0; $i < $worker_num; $i++) {
		$process = new swoole_process('doProcess', false, false); //创建子进程
		$process->useQueue(); //开启队列
		$pid = $process->start();
		$workers[$pid] = $process;
	}

	//进程执行函数
	function doProcess(swoole_process $process) {
		$recv = $process->pop();
		echo "从主进程获取数据：$recv \n";
		#sleep(5);
		$process->exit(0);
	}

	//主进程向子进程添加数据
	foreach ($workers as $pid => $process) {
		$process->push("hello 子进程 $pid \n");
	}

	//等待子进程结束
	for ($i = 0; $i < $worker_num; $i++) {
		$ret = swoole_process::wait(); //等待执行完成
		$pid = $ret['pid'];
		unset($workers[$pid]);
		echo "子进程退出 $pid\n";
	}
